﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AssData;

namespace StandUp.userControls
{
    public partial class EventList : UserControl
    {
        public EventList()
        {
            InitializeComponent();
        }
        DataSelect Mybll = new DataSelect();
        private void EventList_Load(object sender, EventArgs e)
        {
            GetEvent();
        }
        /// <summary>
        /// 获取事件
        /// </summary>
        public void GetEvent()
        {
            BuildList(Mybll.GetEventByDate(dateshowstart.ToString("yyyy-MM-dd"), dateshowend.ToString()));
        }
        private DateTime dateshowstart;
        private DateTime dateshowend;
        /// <summary>
        /// 要显示事件的开始日期
        /// </summary>
        public DateTime DateShowStart
        {
            get { return dateshowstart; }
            set { dateshowstart = value; }
        }
        /// <summary>
        /// 要显示事件的结束日期
        /// </summary>
        public DateTime DateShowEnd
        {
            get { return dateshowend; }
            set { dateshowend = value; }
        }
        void BuildList(DataTable dt)
        {
            flowLayoutPanel1.Controls.Clear();
            _count = dt.Rows.Count;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                SingleEvents se=new SingleEvents();
                se.Name = "AutoSingleEvents"+i.ToString();
                se.Size = new System.Drawing.Size(431, 114);
                se.ID =int.Parse(dt.Rows[i][0].ToString());
                flowLayoutPanel1.Controls.Add(se);
            }
            SetHeight();
        }
        static int _count=0;
        private void flowLayoutPanel1_Resize(object sender, EventArgs e)
        {
            SetHeight();
        }
        void SetHeight()
        {
            int h = 120 * _count;
            if (Width < 865)
                Height = h;
            else
                Height = h / 2 + (_count % 2) * 114;
        }

    }
}
